jQuery(function($){
	jQuery("#datagrid").jqGrid({
		treeGrid: true,
		treeGridModel: 'adjacency',
		ExpandColumn : 'department_code',
	    url:'listDepartmentAsTreeStr.action',//?department.valid_flag=1',  
	    mtype: "POST",
	    datatype: "json",
	    colNames:['部门编码', '部门名称', '上级部门名称', '创建时间', '修改时间'],
	    colModel:[
	       {name:'department_code',index:'department_code'},
	       {name:'department_name',index:'department_name'},
	       {name:'parent_name',index:'parent_name'},
	       {name:'create_time',index:'create_time'},
	       {name:'modify_time',index:'modify_time'}
	    ],
	    pager: '#pager',
	    viewrecords: true,
	    caption: "部门列表",
	    autowidth: true,
	    height: '100%',
	    ondblClickRow: function(id, ri, ci, e){
	    	loadDepartment(id);
	    },
	    serializeGridData: function(data) {
	    	data['department.valid_flag']='1';
	    	data['department.parent_code']=data.nodeid?data.nodeid:'1';
	    	return data;
	    }
	});
	
	jQuery("#datagrid").navGrid(
			'#page',
			{add:false, edit:false, del:true, search:false, refresh:true},
			{},{},
			{
				modal:true,url:"updateValid.action?department.valid_flag=0",
				afterSubmit:function(data, params){
					if(data.responseText) {
						var obj = eval('('+ data.responseText +')');
						var msg = obj.message?obj.message:((obj.success==true || obj.success=='true')?"部门信息删除成功！":"部门信息删除失败！");
						jQuery("#datagrid").clearGridData();
						return [obj.success, msg];
					} else {
						return [true];
					}
				}
			},{},{}
		);
});


function loadDepartment(department_code) {
	showMDialog('loadDepartment.action?edit=true&department.department_code='+department_code,'dialogWidth=850px;dialogHeight=600px');
//	window.open('loadDepartment.action?edit=true&department.department_code='+department_code);
}

function gridReload(){
	jQuery("#datagrid").trigger("reloadGrid");
}